package com.jiandaoshou.utils;

import android.content.Context;
import android.net.ConnectivityManager;
import android.net.NetworkInfo;

/**
 * Created by Administrator on 2017/1/6.
 */

public class NetUtil {

    public static boolean checkNet(Context context) {
        if(context == null) return false;
        boolean isOk = false;
        ConnectivityManager manager = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
        if (manager != null) {
            NetworkInfo[] networks = manager.getAllNetworkInfo();
            for (NetworkInfo network : networks) {
                NetworkInfo.State state = network.getState();
                if (NetworkInfo.State.CONNECTED == state) {
                    isOk = true;
                    break;
                }
            }
        }
        return isOk;
    }
}
